#!/bin/bash
TITLE="MySQL Client"

HOST=$(whiptail --title "$TITLE" --menu "MySQL Host" 22 50 8 \
"127.0.0.1" "localhost" \
"172.16.0.1" "MySQL Master" \
"172.16.0.2" "MySQL Slave 1" \
"172.16.0.3" "MySQL Slave 2"  \
3>&1 1>&2 2>&3)



USER=$(whiptail --inputbox "MySQL User:" 8 60 --title "$TITLE" 3>&1 1>&2 2>&3)

PASSWD=$(whiptail --title "$TITLE" --passwordbox "MySQL Password:" 8 60 3>&1 1>&2 2>&3)

#DATABASE=$(mysqlshow -h$HOST -u$USER | egrep -o "|\w(.*)\w|" | grep -v "Databases" |awk '{print "\""$1"\" \""$1"\""}')
#DATABASE=$(mysqlshow -h$HOST -u$USER | egrep -o "|\w(.*)\w|" | grep -v "Databases" |awk "{print \"$1\" \"$1\"}")

#DB=$(whiptail --title "$TITLE" --menu "MySQL DATABASE" 22 50 8 $DATABASE  3>&1 1>&2 2>&3)

DATABASE=$(whiptail --inputbox "MySQL Database:" 8 60 --title "$TITLE" 3>&1 1>&2 2>&3)

echo $HOST $USER $PASSWD $DATABASE

mysql -h$HOST -u$USER -p$PASSWD $DATABASE
 
exitstatus=$?
if [ $exitstatus = 0 ]; then
    echo "User selected Ok and entered" 
else
    echo "User selected Cancel."
fi
